package com.haiya.mediator.conceptdemo;

import java.util.ArrayList;
import java.util.List;

public class ConcreteMediator extends Mediator {
    private List<Colleague> colleagues;

    public ConcreteMediator() {
        colleagues = new ArrayList<>();
    }

    @Override
    public void register(Colleague colleague) {
        if (!colleagues.contains(colleague)) {
            colleagues.add(colleague);
            colleague.setMediator(this);
        }
    }

    @Override
    public void relay(Colleague colleague, String msg) {
        for (Colleague person : colleagues) {
            if (!person.equals(colleague)) {
                person.receive(msg);
            }
        }
    }
}
